package main

import "fmt"

func main() {

	numbers := []int{0, 1, 2, 3, 4, 5, 6, 7, 8}
	prictSlice(numbers)

	//打印全量的切片
	fmt.Println("numbers ==", numbers)

	// 打印 下标为1到4的切片
	fmt.Println("numbers[1:4] ==", numbers[1:4])

	// 打印 从0开始到3为下标的切片
	fmt.Println("numbers[:3] ==", numbers[:3])

	// 打印 从4开始到底 下标的切片
	fmt.Println("numbers[4:] ==", numbers[4:])

	var numbers2 []int
	prictSlice(numbers2)

	numbers2 = append(numbers2, 0)
	prictSlice(numbers2)

	numbers2 = append(numbers2, 0, 1, 2, 3, 4)
	prictSlice(numbers2)

	numbers3 := make([]int, len(numbers2), (cap(numbers2))*2)

	copy(numbers3, numbers2)

	prictSlice(numbers3)
}

func prictSlice(x []int) {
	fmt.Printf("len=%d cap=%d slice=%v\n", len(x), cap(x), x)

}
